package com.tm.fiverole.result;

import lombok.Data;
import org.apache.poi.ss.formula.functions.T;

/**
 * @author wangSang
 * @create 2022-08-18 13:51
 */
@Data
public class Result<T> {


    private Integer code;
    private String message;
    private T data;


    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(ResultEnum resultEnum, T data) {
        this.code = resultEnum.getCode();
        this.message = resultEnum.getMassage();
        this.data = data;
    }

    public Result(ResultEnum resultEnum) {
        this.code = resultEnum.getCode();
        this.message = resultEnum.getMassage();

    }


    public Result() {
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;

    }

    // 成功回调方法
    public static Result SUCCESS(Object data) {


        return new Result(ResultEnum.SUCCESS, data);
    }
    // 成功回调方法
    public static Result SUCCESS(ResultEnum resultEnum) {


        return new Result(resultEnum.getCode(),resultEnum.getMassage());
    }

    // 成功回调方法
    public static Result SUCCESS() {


        return Result.SUCCESS(ResultEnum.SUCCESS);
    }

    //错误回调方法
    public static Result ERROR() {


        return new Result(ResultEnum.ERROR);

    }

    //自定义失败方法
    public static Result ERROR(Integer code, String massage){

        return new Result(code,massage);
    }

    //参数校验失败方法
    public static Result ERROR(ResultEnum resultEnum){

        return new Result(resultEnum.getCode(),resultEnum.getMassage());
    }

}
